﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Web.ASCX;
using Core.DataAccess;
using SonCa.SocialNetwork.Web.Friends.IPresenters;
using SonCa.SocialNetwork.Web.Friends.Presenters;
using System.ComponentModel.Composition;
using Core.Common;
using Core.Interfaces;

namespace SonCa.SocialNetwork.Web.Friends
{
    public partial class FriendsDisplay : System.Web.UI.Page, IFriendsDisplayPresenter
    {
        private FriendsDisplayPresenter _presenter;

        [Import]
        private IUserSession _userSession;

        protected void Page_Load(object sender, EventArgs e)
        {
            MEFManager.Compose(this);
            _presenter = new FriendsDisplayPresenter();
            string username = Page.RouteData.Values["username"] as string;
            _presenter.Init(this,username);
        }

        protected void repFriends_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ProfileDisplay pdProfileDisplay = e.Item.FindControl("pdProfileDisplay") as ProfileDisplay;
                FriendsProfile friendPro = (FriendsProfile)e.Item.DataItem;
                friendPro.Level = _presenter.GetLevelPathByLevelID(_presenter.GetLevelIDByAccountID(friendPro.AccountID));
                friendPro.Score = _presenter.GetScoreByAccountID(friendPro.AccountID);
                pdProfileDisplay.LoadDisplay(friendPro, _userSession.CurrentUser.AccountID);
            }
        }

        public void LoadFriends(List<FriendsProfile> Accounts)
        {
            rptFriend.DataSource = Accounts;
            rptFriend.DataBind();
        }
    }
}